package com.query.jpa;

import static com.query.util.EntityUtil.nameTableByEntity;

import javax.persistence.EntityManager;
import javax.persistence.Query;

public class QueryJpa {
	
	private StringBuilder sql = new StringBuilder();
	
	EntityManager entityManager;
	
	public QueryJpa(EntityManager entityManager) {
		this.entityManager = entityManager;
	}
	
	public QueryJpa createQuery(Class<?> t){
		StringBuilder tableName = new StringBuilder(nameTableByEntity(t));
		sql.append("select * from ").append(tableName);
		return this;
	}
	
	public void excuteQuery(){
		Query query = entityManager.createQuery(sql.toString());
		query.getSingleResult();
	}

}
